package org.Top101.BM1_linked_list;

/**
 * @Auther: qingle
 * @Date: 2024/8/25-4:17
 * @Description:
 * @version: 1.0
 */
public class BM1_反转链表 {

	public class ListNode{
		int val;
		ListNode next = null;
		public ListNode(int val) {
			this.val = val;
		}
	}

	public ListNode ReverseList(ListNode head) {
			ListNode prev = null;
			ListNode cur = head;
			ListNode next = null;
			while (cur != null) {
				// 保存当前节点的下一个节点
				next = cur.next;
				cur.next = prev;
				prev = cur;
				cur = next;
			}
			return next;
	}
}
